// JavaScript Document
 function replace3(s){
	s = s.replace(/\[\/URL\]/g, '</a><br/>');
	s = s.replace(/\[img\]/g, '<img   src="');
	s = s.replace(/\[\/img\]/g, '" /></a><br/>');
	s = s.replace(/\[IMG\]/g, '<img   src="');
	s = s.replace(/\[\/IMG\]/g, '" /></a><br/>');
return s;}
function getdata(id)
{	
	if(id!=""){
	tinyMCE.get('chap_content').setProgressState(1);
	kool=new KoolAjaxRequest({
							method:"post",
							url:"index.php",
							 onDone:function(result)
							 {	 
								tinyMCE.get('chap_content').setProgressState(0);
							 	tinyMCE.get('chap_content').setContent(result);
							 }
							 });
	kool.addArg("id",id)
	kool.addArg("act","getdata")
	kool.addArg("module","manga")
	kool.addArg("ext","chap")
	koolajax.sendRequest(kool)
	}
}

function changeplaylist(id)
{
	if(id!=""){
	location.href='http://manga24h.com/manga/upload/get='+id;
	}
}
function add_chap()
{
	n=document.getElementById("news_cat").value;
	chapname=document.getElementById("chap_name").value;
	chapnamethutu=document.getElementById("chap_name_thutu").value;
	chapday=document.getElementById("chap_day").value;
	chapnamedownload=document.getElementById("chap_name_download").value;
	
	chapcontent =replace3(tinyMCE.get('chap_content').getContent());
	
	is=document.getElementById("index").value;
	sm=document.getElementById("seo_manga").value;
	chhot=document.getElementById('hot').checked;
   	if(chhot){hot=1; }else{ hot=0;}
	
	chnew=document.getElementById('new1').checked;
   	if(chnew){news=1; }else{ news=0;}
	
	
	if(n=="")
	{
	alert("Xin vui lòng chọn Manga !!");
	return false;
	}

	if(chapcontent=="")
	{
		alert("Xin vui lòng nhập nội dung cho chapter này !");
		return false;
	}
	
	if(chapnamethutu=="" || chapname=="")
	{
		alert("Nhập Tên Chương và Thứ Tự Chương");
		return false;
	}
	
	
	tinyMCE.get('chap_content').setProgressState(1);
	kool=new KoolAjaxRequest({
							method:"post",
							url:"index.php",
							 onDone:function(result)
							 {	 
							 	alert(result);
							tinyMCE.get('chap_content').setProgressState(0);
							document.getElementById("index").value="";
							//	location.reload();
							 }
							 });
	kool.addArg("chap_news",n)
/*	kool.addArg("security",code) */
	kool.addArg("chap_name",chapname)
	kool.addArg("chap_name_thutu",chapnamethutu)
	kool.addArg("chap_name_download",chapnamedownload)
	kool.addArg("chap_content",chapcontent)
	kool.addArg("chapday",chapday)
	kool.addArg("show",is)
	kool.addArg("seomanga",sm)
	kool.addArg("hot",hot)
	kool.addArg("new",news)
	kool.addArg("act","add")
	kool.addArg("module","manga")
	kool.addArg("ext","chap")
	koolajax.sendRequest(kool)
	
}
function delete_chap()
{	n=document.getElementById("news_cat").value;
	chapid=document.getElementById("chap_id").value;
	if(n=="")
	{
		alert("Chọn chapter bạn muốn delete");
		return false;
	}
	if(confirm('Bạn có chắc bạn muốn xóa chapter này ?'))
	{
	kool=new KoolAjaxRequest({
							method:"get",
							url:"index.php",
							 onDone:function(result)
							 {	 
							 	alert(result);
								location.reload();
							 }
							 });
	kool.addArg("id",chapid)
	kool.addArg("mg",n)
	kool.addArg("act","delete")
	kool.addArg("module","manga")
	kool.addArg("ext","chap")
	koolajax.sendRequest(kool)
	}
	
}
function update_chap()
{	n=document.getElementById("news_cat").value;
	chid=document.getElementById("chap_id").value;
	chname=document.getElementById("chap_name").value;
	chtt=document.getElementById("chap_name_thutu").value;
	chdl=document.getElementById("chap_name_download").value;
	
	chap_content = replace3(tinyMCE.get('chap_content').getContent());
	
	is=document.getElementById("index").value;
	sm=document.getElementById("seo_manga").value;
	
	chhot=document.getElementById('hot').checked;
   	if(chhot){hot=1; }else{ hot=0;}
	
	chnew=document.getElementById('new1').checked;
   	if(chnew){news=1; }else{ news=0;}
	
	
	chul=document.getElementById('block').checked;
   	if(chul){ul=1; }else{ ul=0;}
	

	if(n=="" || chid=="" )
	{
		alert("Chọn Chapter trong list Chapter để cập nhật !!!");
		return false;
	}
	tinyMCE.get('chap_content').setProgressState(1);
	kool=new KoolAjaxRequest({
							method:"post",
							url:"index.php",
							 onDone:function(result)
							 {	 
							 	alert(result);
								tinyMCE.get('chap_content').setProgressState(0);
								document.getElementById('hot').checked=false;
									document.getElementById('new').checked=false;
									document.getElementById("index").value="";
									
							//	location.reload();
							 }
							 });
	kool.addArg("chap_news",n)
/*	kool.addArg("security",code) */
	kool.addArg("chap_id",chid)
	kool.addArg("chap_name",chname)
	kool.addArg("chap_thutu",chtt)
	kool.addArg("chap_download",chdl)
	kool.addArg("chap_content",chap_content)
	kool.addArg("show",is)
	kool.addArg("seomanga",sm)
	kool.addArg("hot",hot)
	kool.addArg("new",news)
	kool.addArg("block",ul)
	kool.addArg("act","edit")
	kool.addArg("module","manga")
	kool.addArg("ext","chap")
	koolajax.sendRequest(kool)
	
}

	
   function geturl()
  {			
  	 		
			fd=document.getElementById("url").value;
			if(fd=="")
			{
			alert("Nhập vào url của vnsharing để get link ảnh !!");
			return false;
			}
  			tinyMCE.get('chap_content').setProgressState(1);
	 		var request=new KoolAjaxRequest({
			method:"post",
			url:"index.php",
			onOpen:function()
			{
			
			},
			onDone:function(result)
			{	
				//tinyMCE.get('chap_content').setProgressState(0);
				
				tinyMCE.get('chap_content').setContent(result);
				tinyMCE.get('chap_content').setProgressState(0);
				finddata=result.indexOf('vnsharing.net');
				
				/*
				 if(finddata==-1){
				 alert("co link hinh anh cua vnsharing, hay doi de download hinh anh ve server");
				 download();
				 }else{
				
				 }
				*/
				return false;
				
				
			}
					 
			});
			request.addArg('module','manga');
			request.addArg('ext','chap');
			request.addArg('act','geturl');
		   	request.addArg('url',fd);
			koolajax.sendRequest(request);
			return false;		
 }	
